package com.shivandragon.utils;

import com.mongodb.BasicDBObject;
import com.mongodb.DBObject;

public class MongoModelUtils {

	public static void addFiledValue(DBObject modelObject, String fieldName, Object fieldValue, boolean isUpdate) {
		if(isUpdate) {
			DBObject setDbObject = null;
			if(modelObject.get("$set") != null) {
				setDbObject = (DBObject) modelObject.get("$set");
			} else {
				setDbObject = new BasicDBObject();
				modelObject.put("$set", setDbObject);
			}
			setDbObject.put(fieldName, fieldValue);
		} else {
			modelObject.put(fieldName, fieldValue);
		}
	}
}
